home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Sample Code / Snippets / Devices / Disk Icons / compgetinfo.c
Encoding:
C/C++ Source or Header  |  1992-07-15  |  3.2 KB  |  133 lines  |  [TEXT/KAHL]

  1.  
  2. /*    this is the data structure pointed to in the result of the
  3.     disk driver call csCode=21 (get ICN#/comment).  This call
  4.     works on all devices.
  5. */
  6.  
  7. typedef struct TInfoBlk {
  8.     unsigned char    icon[128];        /* icon */
  9.     unsigned char    mask[128];        /* mask */
  10.     Str255            infoString;        /* info string (for get info) */
  11. } TInfoBlk,*TInfoPtr;
  12.  
  13. void GetDiskInfo(short driverRefNum,short driveNum,TInfoPtr *dataBlk);
  14. void DrawInfo(TInfoPtr infoBlock);
  15. void GetAllInfo(void);
  16. void GetAllInfoYourWay(void);
  17.  
  18.  
  19. void main(void)
  20. {
  21.     WindowPtr theWindow;
  22.     Rect wBounds;
  23.  
  24. #ifdef THINK_C
  25.     InitGraf(&thePort);
  26. #else
  27.     InitGraf(&qd.thePort);
  28. #endif
  29.     InitFonts();
  30.     InitWindows();
  31.     InitMenus();
  32.     TEInit();
  33.     InitDialogs(nil);
  34.     FlushEvents(everyEvent,0);
  35.     InitCursor();
  36.     
  37.     SetRect(&wBounds,40,40,100,100);
  38.     theWindow = NewWindow (nil,&wBounds,(StringPtr)"\pIcons",true,documentProc,
  39.                 (WindowPtr)(-1),true,0L);
  40.     SetPort(theWindow);
  41.     GetAllInfo();
  42.     DisposeWindow(theWindow);
  43. }
  44.  
  45.  
  46. /*    This routine traverses the currently mounted volumes
  47.     index using PBHGetVInfo().  The drive # and device
  48.     driver number for each volume is extracted from the
  49.     parameter block, and passed into GetDiskInfo() to
  50.     call the disk drivers.
  51.     
  52.     Once the data has been retrieved, the icon is plotted
  53. */
  54.  
  55. void GetAllInfo(void)
  56. {
  57.     HParamBlockRec vBlock;    /* volume parameter block used to traverse mounted vols */
  58.     OSErr err;
  59.     TInfoPtr dataBlk;        /* pointer used to point to result of csCode=21 call */
  60.     
  61.     vBlock.volumeParam.ioNamePtr = nil;
  62.     vBlock.volumeParam.ioVRefNum = 0;
  63.     vBlock.volumeParam.ioVolIndex = 1;
  64.     
  65.     do {
  66.         err = PBHGetVInfo (&vBlock,false);
  67.         vBlock.volumeParam.ioVolIndex++;
  68.         if (err==noErr) {
  69.             GetDiskInfo(vBlock.volumeParam.ioVDRefNum,
  70.                         vBlock.volumeParam.ioVDrvInfo,&dataBlk);
  71.             if (dataBlk)
  72.                 DrawInfo(dataBlk);
  73.         }
  74.     } while (err==noErr);
  75. }
  76.  
  77.  
  78. /*    GetDiskInfo() makes the call to the volume's driver to get the
  79.     volume icon and info string.  A pointer to this data is returned
  80.     by reference in dataBlk
  81.     
  82.     This routine tries to call the disk's driver with csCode=22,
  83.     which attempts to get info on a specific physical volume.
  84.     
  85.     If the csCode=22 call fails, I call csCode=21 to get the generalized
  86.     media icon.
  87.     
  88.     Both calls are documented in IM V-470
  89. */
  90.  
  91. void GetDiskInfo(short driverRefNum,short driveNum,TInfoPtr *dataBlk)
  92. {
  93.     CntrlParam pBlock;
  94.     OSErr err;
  95.     
  96.     pBlock.ioVRefNum = driveNum;
  97.     pBlock.ioCRefNum = driverRefNum;
  98.     pBlock.csCode = 22;
  99.     
  100.     err = PBControl(&pBlock,false);
  101.     if (err==controlErr) {
  102.         pBlock.ioVRefNum = driveNum;
  103.         pBlock.ioCRefNum = driverRefNum;
  104.         pBlock.csCode = 21;
  105.         err = PBControl(&pBlock,false);
  106.     }
  107.     
  108.     if (err==noErr)
  109.         *dataBlk = (TInfoPtr) *(Ptr *)pBlock.csParam; /* messy way to get the locn out */
  110.     else *dataBlk = nil;
  111. }
  112.  
  113.  
  114.  
  115. /*    this routine uses CopyBits to draw the icon on the screen (ignoring the mask and
  116.     the info string).  Make sure you put up a window and call SetPort() first!
  117. */
  118.  
  119. void DrawInfo(TInfoPtr infoBlock)
  120. {
  121.     BitMap iconMap;
  122.     Rect destRect;
  123.     
  124.     iconMap.baseAddr = (Ptr)infoBlock;
  125.     iconMap.rowBytes = 4;
  126.     SetRect(&iconMap.bounds,0,0,32,32);
  127.     SetRect(&destRect,0,0,32,32);
  128.     OffsetRect(&destRect,10,10);
  129.     CopyBits(&iconMap,&thePort->portBits,&iconMap.bounds,&destRect,
  130.             srcCopy,nil);
  131.     while (!Button());
  132.     while (Button());
  133. }